<template>
<div class="user">
    <el-form size="small" ref="form" :model="form" label-width="150px">
      <el-form-item :label="$t('plus.enable_coupon_deduction')" prop="isCoupon">
        <el-switch v-model="form.isCoupon"></el-switch>
        <!-- <p>注：如需使用分销功能必须在 [分销中心 - 分销设置] 中开启</p> -->
      </el-form-item>
      <el-form-item :label="$t('plus.enable_distribution1')" prop="isAgent">
        <el-switch v-model="form.isAgent"></el-switch>
        <!-- <p>注：如需使用分销功能必须在 [分销中心 - 分销设置] 中开启</p> -->
      </el-form-item>
      <el-form-item :label="$t('plus.enable_point_deduction')" prop="isPoint">
        <el-switch v-model="form.isPoint"></el-switch>
        <!-- <p>注：如需使用分销功能必须在 [分销中心 - 分销设置] 中开启</p> -->
      </el-form-item>
      <!--提交-->
      <el-form-item
        ><el-button type="primary" @click="onSubmit" :loading="loading"
          >{{$t('plus.save')}}</el-button
        ></el-form-item
      >
    </el-form>
  </div>
</template>

<script>
import AssembleApi from "@/api/assemble.js";
export default {
  data() {
    return {
      form: {
        isCoupon: false,
        isDistribution: false,
        isPoint: false
      },
      setting: [],
      loading: false
    };
  },
  created() {
    /*获取列表*/
    this.getSetting();
  },
  methods: {
    /*获取设置*/
    getSetting() {
      let self = this;
      let Params = {};
      AssembleApi.getSetting(Params, true).then(res => {
        self.loading = false;
        self.form = res.data;
      }).catch(error => {});
    },
    /*点击保存*/
    onSubmit() {
      let self = this;
      let params = self.form;
      self.loading = true;
      AssembleApi.saveSetting(params, true).then(data => {
        self.loading = false;
        if (data.code == 1) {
          ElMessage({
            message: $t("plus.save_success"),
            type: "success"
          });
          self.getSetting();
        } else {
          self.loading = false;
        }
      }).catch(error => {
        self.loading = false;
      });
    }
  }
};
</script>

